/**
 * @Author:  renyc
 * @Date: 2022年12月20日16:53:18
 */

import Overlay from "../Overlay";
import LayerType from "../../layer/LayerType";

/**
 * @class EntityOverlay
 * 
 * @description Cesium.Entity类型的Overlay
 * 
 */
class EntityOverlay extends Overlay{
    constructor(){
        super();
    }

    /**
     * 将Layer挂载到Viewer上(内部方法)
     * @protected
     * @Override
     */
    _attach(){
        if(!this._delegate){
            return false;
        }
        if(this._layer.type!=LayerType.VECTOR){
             return false;
        }

        if(!this._layer._source){
            return false;
        }
        if(!this._layer._source._delegate){
            return false;
        }
        let dataSource = this._layer._source._delegate;
        if(!dataSource){
            return false;
        }

        if(this._delegate){
            dataSource.entities.add(this._delegate);
        }

        return true;
     }

     /**
      * 将Layer从Viewer上卸载(内部方法)
      * @protected
      * @Override
      */
     _detach(){
        if(this._layer._source){
            if(this._layer._source._delegate){
                let dataSource = this._layer._delegate;        
                if(!dataSource){
                    return;
                }
                if(this._delegate){
                    dataSource.entities.remove(this._delegate);
                }
            }
        }        
    }
}

export default EntityOverlay
